package com.qingge.springboot.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingge.springboot.controller.dto.UserDTO;
import com.qingge.springboot.entity.Teacher;
import com.qingge.springboot.entity.vo.TeacherCourseVo;
import com.qingge.springboot.mapper.TeacherMapper;
import com.qingge.springboot.service.ITeacherService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author: Mr.Wu
 * @create: 2022-12-13 10:16
 **/
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {

    @Override
    public List<TeacherCourseVo> selectCourse(Integer teacherId){
        List<TeacherCourseVo> teacherCourseVos = this.baseMapper.selectByTeacherId(teacherId);
        return teacherCourseVos;
    }

    @Override
    public UserDTO login(String username, String password) {
        LambdaQueryWrapper<Teacher> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Teacher::getUsername,username);
        lambdaQueryWrapper.eq(Teacher::getPassword,password);
        Teacher teacher = this.baseMapper.selectOne(lambdaQueryWrapper);
        UserDTO userDTO = new UserDTO();
        if(teacher!=null){
            userDTO.setNickname(teacher.getTeacherName());
            BeanUtils.copyProperties(teacher,userDTO);
        }
        return userDTO;
    }
}
